package cn.oms.manage.dao.persist.repository.impl;

import cn.oms.commons.pojo.vo.PageData;
import cn.oms.commons.util.PageInfoToPageDataConverter;
import cn.oms.manage.dao.persist.mapper.DoctorMapper;
import cn.oms.manage.dao.persist.repository.IDoctorRepository;
import cn.oms.manage.pojo.entity.Doctor;
import cn.oms.manage.pojo.vo.DoctorListVO;
import cn.oms.manage.pojo.vo.DoctorNameListVO;
import cn.oms.manage.pojo.vo.DoctorStandardVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class DoctorRepositoryImpl implements IDoctorRepository {

    @Autowired
    private DoctorMapper doctorMapper;

    public DoctorRepositoryImpl() {
        log.debug("创建数据访问实现类对象：CustomerRepositoryImpl");
    }

    @Override
    public int insert(Doctor doctor) {
        log.debug("开始执行【插入订单】的数据访问，参数：{}", doctor);
        return doctorMapper.insert(doctor);
    }

    @Override
    public int insertBatch(List<Doctor> doctorList) {
        log.debug("开始执行【批量插入订单】的数据访问，参数：{}", doctorList);
        return doctorMapper.insertBatch(doctorList);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据ID删除相册】的数据访问，参数：{}", id);
        return doctorMapper.deleteById(id);
    }

    @Override
    public int update(Doctor doctor) {
        log.debug("开始执行【修改医生信息】的数据访问，参数：{}", doctor);
        return doctorMapper.updateById(doctor);
    }

    @Override
    public DoctorStandardVO getStandardById(Long id) {
        log.debug("开始执行【根据ID查询药品信息】的数据访问，参数：{}", id);
        return doctorMapper.getStandardById(id);
    }

    @Override
    public int countByName(String name) {
        log.debug("开始执行【统计匹配名称的相册的数量】的数据访问，参数：{}", name);
        QueryWrapper<Doctor> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        return doctorMapper.selectCount(queryWrapper);
    }

    @Override
    public List<DoctorNameListVO> listDoctorName() {
        return doctorMapper.listDoctorName();
    }


    @Override
    public int countByDepartmentId(Long departmentId) {
        log.debug("开始执行【统计匹配相册的图片的数量】的数据访问，相册：{}", departmentId);
        QueryWrapper<Doctor> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("department_id", departmentId);
        return doctorMapper.selectCount(queryWrapper);
    }


    @Override
    public PageData<DoctorListVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询药品列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<DoctorListVO> list = doctorMapper.list();
        PageInfo<DoctorListVO> pageInfo = new PageInfo<>(list);
        PageData<DoctorListVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }
}
